<?php
/*
if($id==283368){
	ini_set("display_errors", "On");
	error_reporting(E_ALL | E_STRICT);
}
if($id==283648){
	print_r($softArr['adminstatus']);
	exit;
}
*/

$dedeCommon = new DedeCommon();
$masterCommon = new MasterCommon();
$softArr = $masterCommon->getSoftContent($id);
if(count($softArr)<=0){
	$sql = "SELECT * FROM `mumayi_soft` WHERE id=$id AND adminstatus!=20  AND  sid=0 AND (status=-2 OR status>0) ";
	$newquery = $DEVDB->query($sql);
	$softArr = $DEVDB->fetch_array($newquery);
}

//黑名单，直接404
if(!in_array($softArr['adminstatus'],array(0,1,2))){
	 Header("Location: http://www.mumayi.com/404.html?dNotId=".$id);
	 exit;
}
//如果此软件是更改过包的软件，且状态是审核中
if($softArr['status']==0 ){
	 //如果不是换包的软件，直接提示404
	 if($softArr['editcontent']==''){
		 Header("Location: http://www.mumayi.com/404.html?dNotId=".$id);
		 exit;
	 }else{
		 //如果是换过软件包的，先查看没有历史版本，如果没有证明是新发的软件，直接提示404
		 $ifsoftArr = $DEVDB->fetch_first("SELECT id FROM `mumayi_soft` WHERE sid=$id limit 0,1");
		 if(!$ifsoftArr){
			 Header("Location: http://www.mumayi.com/404.html?dNotId=".$id);
			 exit;
		 }

	 }

}else{
	//如果软件不在下架，VIP直接上架，编辑审核上架 这三种状态下，提示最终页404
	if(!in_array($softArr['status'],array(-2,1,2))){
		 Header("Location: http://www.mumayi.com/404.html?dNotId=".$id);
		 exit;
	}
}



$oldIcon = $GLOBALS['UPLOAD_DIR'].$softArr['icon'];
$newIcon = $GLOBALS['UPLOAD_DIR'].dirname($softArr['icon']).'/litpicH_'.basename($softArr['icon']);
$oldimgArr = getimagesize($oldIcon);

//如果ICON大于72，且72的ICON不存在，则生成缩图
if($oldimgArr[0]>72 && (!is_file($newIcon))){
	$a = imageThumb($oldIcon,$newIcon,72,72,1);
}
if(is_file($newIcon)){
	$icon = GetRandImages(str_replace($GLOBALS['UPLOAD_DIR'],'',$newIcon));
}else{
	$icon = GetRandImages($softArr['icon']);
}
//$icon = GetRandImages($softArr['icon']);



//处理封面图片
$showImg = $imgdir = $GLOBALS['UPLOAD_DIR'].$softArr['surface'];
$surfaceScreen = (int)$softArr['screen']; //是否横屏

//查看是否存在没有加水印的图
$nologoFile = dirname($imgdir).'/nologo/nologo_'.basename($imgdir);
$nologoRotateFile = dirname($imgdir).'/nologo/nologo_90c_'.basename($imgdir);


$iconimgArr = getimagesize($showImg);

//横屏宽大于高的时候，进行旋转
if($iconimgArr[0] > $iconimgArr[1] ){

	//查看没有做90度的旋转
	if(!is_file($nologoRotateFile)){

		if(!is_file($nologoFile)){
			$nologoFile = $imgdir;
		}

		//做90度旋转
		$re = rotateImg($nologoFile,$nologoRotateFile);

		if($re){
			$re = imageThumb($nologoRotateFile,$nologoRotateFile,230,408,1);

		}
	}
	$showImg = $nologoRotateFile;
	$softArr['surface'] = str_replace($GLOBALS['UPLOAD_DIR'],'',$nologoRotateFile);

}else{
	if(is_file($nologoFile)){
		if(!is_file($nologoRotateFile)){
			$a = imageThumb($nologoFile,$nologoRotateFile,230,408,1);
		}
		$showImg = $nologoRotateFile;
		$softArr['surface'] = str_replace($GLOBALS['UPLOAD_DIR'],'',$nologoRotateFile);
	}
}


//取到图片宽高
list($surfaceWidth, $surfaceHeight, $type, $attr) = @getimagesize($showImg);

$surface = GetRandImages($softArr['surface']);


//分享
$shareurls = urlencode('http://www.mumayi.com/android-'.$id.'.html');
$sharetitles = urlencode($softArr['title'].' 不错，推荐给大家~'.$softArr['recommend']).' ';

$sharelist ='<a href="http://service.weibo.com/share/share.php?title='.$sharetitles.'&url='.$shareurls.'" target="_blank" title="分享到新浪微博" class="sinawb"></a>
<a href="http://v.t.qq.com/share/share.php?title='.$sharetitles.'&url='.$shareurls.'" target="_blank" title="分享到腾讯微博" class="qqwb"></a>
<a href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='.$shareurls.'%2F&title='.$sharetitles.'&pics=&summary=" target="_blank" class="qqk"  title="分享到QQ空间" ></a>';


$urls = getUrls(array(1,2,3));
$updatetime = ChangeDate($softArr['created']);
$typeid = $softArr['cid'];
$nowtimes = time();
$exptime = 3600*3;
$nowdate = date('Y-m-d',time());
//处理下架逻辑
if($softArr['status']==-2){
	$isdelete = 1;
	$qrcode = 'http://imga.mumayi.com/android/img_mumayi/2012/12/21/0/1/1.png';
	$downloadUrl = 'http://down.mumayi.com/1';
}else{
	$isdelete = 0;
	//处理二维码图片
	$qrcode = GetRandImages($softArr['qrcode']);
	$downloadUrl = 'http://down.mumayi.com/'.$id;
}

//取到软件包名
if($softArr['packagename']){
	$packagename = $softArr['packagename'];
}else{
	$packagename = '没取到包名';
}

//取到开者名称
if($softArr['uid']){
	$uid = $softArr['uid'];
	$developername  = $softArr['developername'];
	if($developername == ''){
		$numrow = $DEVDB->fetch_first("SELECT username,company,provide FROM `mumayi_member`  WHERE `uid`=$uid");
		//如果开发者是公司（值为1）,直接显示公司名. 个人则显示注册的用户名
		if($numrow['provide']){
			$developername  = $numrow['company'];
		}else{
			$developername  = $numrow['username'];
		}
		$developer = addslashes($developername);
		$dedeCommon->getSoftVal($id,'developername',$developer);
		$DEVDB->query("UPDATE mumayi_soft SET developername = '$developer'  WHERE `id`=$id");
	}
}else{
	if($softArr['developername']!=''){
		$developername  = $softArr['developername'];
	}else{
		$datas = readCacheArray('developername.php');
		$developername  = $datas[rand(0,662)];
		$developer = addslashes($developername);
		$dedeCommon->getSoftVal($id,'developername',$developer);
		$DEVDB->query("UPDATE mumayi_soft SET developername = '$developer'  WHERE `id`=$id");
	}
}



//软件所在分类
$datas = readCacheArray('typeclass.php');
$typename = $datas[$softArr['cid']]['typename'];
$typedirurl = trim(str_replace('{cmspath}','',$datas[$softArr['cid']]['typedir']));
if(3 == $datas[$softArr['cid']]['reid']){

	$parenturl = '/android/app';
	$navNumber = 1;
	$parentTypename = '软件';
}else{

	$parenturl = '/android/game';
	$navNumber = 2;
	$parentTypename = '游戏';
}


$archiveArr = $WebDB->fetch_first("SELECT keywords,description FROM `dede_archives` WHERE id=$id");

$softTitle = $softArr['title'].'V'.$softArr['versionname'].'_'.$typename.'_'.$parentTypename.'_木蚂蚁安卓市场';
$softKeywords  = $archiveArr['keywords'];
$softDescription  = preg_replace('/\"/',"'",cutword($archiveArr['description'],180));

//取到游戏和应用排行榜
$sql = 'SELECT id,icon,softsize,frontdownload,title,versionname FROM `mumayi_soft` WHERE sid =0 AND status =2 AND adminstatus!=20 ORDER BY `frontdownload` DESC LIMIT 0 , 10';
$query = $DEVDB->query($sql);
$i = 0;
$allRankData = array();
while(@$row = $DEVDB->fetch_array($query)) {
		$allRankData[$i]['id'] = $row['id'];
		$baseIcon = dirname($row['icon']).'/litpicH_'.basename($row['icon']);
		$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
		if(is_file($iconDir)){
			$allRankData[$i]['icon'] = GetRandImages($baseIcon);
		}else{
			$allRankData[$i]['icon'] = GetRandImages($row['icon']);
		}
		$allRankData[$i]['softsize'] = $row['softsize'];
		$allRankData[$i]['frontdownload'] = FormatDownNum($row['frontdownload']);
		$allRankData[$i]['title'] = $row['title'];
		$allRankData[$i]['versionname'] = $row['versionname'];
		$i++;
}


//取到应用排行榜
$resultfile = readCacheArray('softclass.php');
$idlist = implode(',',$resultfile);
$sql = "SELECT * FROM `mumayi_soft` WHERE sid =0 AND status =2 AND adminstatus!=20 AND cid IN ($idlist) ORDER BY  `frontdownload` DESC LIMIT 0 , 10";
$query = $DEVDB->query($sql);
$i = 0;
$softRankData = array();
while(@$row = $DEVDB->fetch_array($query)) {
		$softRankData[$i]['id'] = $row['id'];
		$baseIcon = dirname($row['icon']).'/litpicH_'.basename($row['icon']);
		$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
		if(is_file($iconDir)){
			$softRankData[$i]['icon'] = GetRandImages($baseIcon);
		}else{
			$softRankData[$i]['icon'] = GetRandImages($row['icon']);
		}
		$softRankData[$i]['softsize'] = $row['softsize'];
		$softRankData[$i]['frontdownload'] = FormatDownNum($row['frontdownload']);
		$softRankData[$i]['title'] = $row['title'];
		$softRankData[$i]['versionname'] = $row['versionname'];
		$i++;
}


//取到游戏排行榜
$resultfile = readCacheArray('gameclass.php');

$idlist = implode(',',$resultfile);
$sql = "SELECT * FROM `mumayi_soft` WHERE sid =0 AND status =2 AND adminstatus!=20 AND cid IN ($idlist) ORDER BY `frontdownload` DESC LIMIT 0 , 10";

$query = $DEVDB->query($sql);
$i = 0;
$gameRankData = array();
while(@$row = $DEVDB->fetch_array($query)) {
		$gameRankData[$i]['id'] = $row['id'];
		$baseIcon = dirname($row['icon']).'/litpicH_'.basename($row['icon']);
		$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
		if(is_file($iconDir)){
			$gameRankData[$i]['icon'] = GetRandImages($baseIcon);
		}else{
			$gameRankData[$i]['icon'] = GetRandImages($row['icon']);
		}
		$gameRankData[$i]['softsize'] = $row['softsize'];
		$gameRankData[$i]['frontdownload'] = FormatDownNum($row['frontdownload']);
		$gameRankData[$i]['title'] = $row['title'];
		$gameRankData[$i]['versionname'] = $row['versionname'];
		$i++;
}


//Head头部推广应用
$nowtimes = time();
$headscroll_id = "newheadscroll1";

$scrollResult = $dedeCommon->addGet($headscroll_id);
$headlisthtml = '';
//如果过期，重新生成一次，再写入缓存
if($scrollResult == ''){
	

	$sql = "SELECT versionname,id,title,icon FROM `mumayi_soft` WHERE sid =0 AND status =2 AND adminstatus!=20 AND adminstatus!=20 AND ext_attribute LIKE '%b%' ORDER BY rand()   LIMIT 0 , 8";
	$query = $DEVDB->query($sql);
	while(@$softrow = $DEVDB->fetch_array($query)) {

			$baseIcon = dirname($softrow['icon']).'/litpicH_'.basename($softrow['icon']);
			$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
			if(is_file($iconDir)){
				$showlogo = GetRandImages($baseIcon);
			}else{
				$showlogo = GetRandImages($softrow['icon']);
			}
			$versionname = $softrow['versionname'];
			$title = $softrow['title'];
			$id = $softrow['id'];

			$headlisthtml.='<li>
			<a class="img72_72" title="'.$title.' V'.$versionname.'" target="_blank" href="http://www.mumayi.com/android-'.$id.'.html">
				<img alt="'.$title.' V'.$versionname.'"  width="72" height="72" src="'.$showlogo.'">
				<div class="green72_72"></div>
			</a>
			<div class="tit50">
				<a title="'.$title.' V'.$versionname.'" target="_blank" href="http://www.mumayi.com/android-'.$id.'.html">'.$title.'</a>
			</div>
		</li>';

	}

	$dedeCommon->addTimeSet($headscroll_id,$exptime,$headlisthtml);

}else{

	$headlisthtml = $dedeCommon->addGet($headscroll_id);
}




//Head头部游戏推广应用
$nowtimes = time();
$newgamelist_web = "newgamelist_web";
$newgamelist_pc = "newgamelist_pc";
$gamelist_web_html = $dedeCommon->addGet($newgamelist_web);
$gamelist_pc_html = $dedeCommon->addGet($newgamelist_pc);


//如果过期，重新生成一次，再写入缓存
if($gamelist_web_html == ''){
	$webgamedateFile = "/mnt/html/shell/cache/webgamedate_web.txt";
	$pcgamedateFile = "/mnt/html/shell/cache/pcgamedate_pc.txt";

	$gamelist_web_html = @file_get_contents($webgamedateFile);
	$gamelist_pc_html = @file_get_contents($pcgamedateFile);

	$dedeCommon->addTimeSet($newgamelist_web,$exptime,$gamelist_web_html);
	$dedeCommon->addTimeSet($newgamelist_pc,$exptime,$gamelist_pc_html);

}




//Right右侧推广应用
//缓存ID
$redis_id="newaddsoftlist1";
$result = $dedeCommon->addGet($redis_id);
$rightlisthtml = '';
//如果过期，重新生成一次，再写入缓存
if($result==''){
	

	$sql = "SELECT versionname,id,title,icon FROM `mumayi_soft` WHERE sid =0 AND status =2 AND adminstatus!=20 AND adminstatus!=20 AND ext_attribute LIKE '%c%' ORDER BY softsort DESC LIMIT 0 , 9";
	$query = $DEVDB->query($sql);
	while(@$softrow = $DEVDB->fetch_array($query)) {

			$baseIcon = dirname($softrow['icon']).'/litpicH_'.basename($softrow['icon']);
			$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
			if(is_file($iconDir)){
				$showlogo = GetRandImages($baseIcon);
			}else{
				$showlogo = GetRandImages($softrow['icon']);
			}
			$versionname = $softrow['versionname'];
			$title = $softrow['title'];
			$id = $softrow['id'];

			$rightlisthtml.='<li><a class="img72_72" title="'.$title.'V'.$versionname.'" target="_blank" href="http://www.mumayi.com/android-'.$id.'.html">
                              <img alt="'.$title.'V'.$versionname.'"  width="72" height="72" src="'.$showlogo.'">
                              <div class="fff72_72"></div>
                          </a><div class="tit50">
                              <a title="'.$title.'V'.$versionname.'" target="_blank" href="http://www.mumayi.com/android-'.$id.'.html">'.$title.'V'.$versionname.'</a>
                          </div>
                      </li>';

	}

	//写入redis,并设定时间
	$dedeCommon->addTimeSet($redis_id,$exptime,$rightlisthtml);

}else{
	$rightlisthtml = $dedeCommon->addGet($redis_id);

}


//右侧推荐9个 MPK游戏,取到缓存ID
$mpkgamedateFile = "/mnt/html/shell/cache/mpkgamedate.txt";
$mpkgamedate_html = file_get_contents($mpkgamedateFile);
$allMpk = explode(',',$mpkgamedate_html);

//右侧推荐9个 MPK游戏
$rightID = implode(',',array_slice($allMpk, 0,9));


//缓存ID
$redis_id = "softrightmpk";
$data = array();
$result = $dedeCommon->addGet($redis_id);
$rightmpkhtml = '';

if($result == ''){
	$sql = "SELECT versionname,id,title,icon FROM `mumayi_soft` WHERE adminstatus=20 AND id IN ($rightID) ORDER BY id DESC LIMIT 0 , 9";
	$query = $DEVDB->query($sql);
	while(@$softrow = $DEVDB->fetch_array($query)) {

			$baseIcon = dirname($softrow['icon']).'/litpicH_'.basename($softrow['icon']);
			$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
			if(is_file($iconDir)){
				$showlogo = GetRandImages($baseIcon);
			}else{
				$showlogo = GetRandImages($softrow['icon']);
			}
			$versionname = $softrow['versionname'];
			$title = $softrow['title'];
			$id = $softrow['id'];
			$rightmpkhtml.='<li><a class="img72_72" title="'.$title.'V'.$versionname.'" target="_blank" href="http://mpk.mumayi.com/'.$id.'.html">
								  <img alt="'.$title.'V'.$versionname.'"  width="72" height="72" src="'.$showlogo.'">
								  <div class="fff72_72"></div>
							  </a><div class="tit50">
								  <a title="'.$title.'V'.$versionname.'" target="_blank" href="http://mpk.mumayi.com/'.$id.'.html">'.$title.'V'.$versionname.'</a>
							  </div>
						  </li>';

			//写入redis,并设定时间
			$exptime = 2*3600;
			$dedeCommon->addTimeSet($redis_id,$exptime,$rightmpkhtml);
	}
}else{
	$rightmpkhtml = $dedeCommon->addGet($redis_id);
}


//Right右侧新闻
//缓存ID
$redis_id="rightarticlelist";
$result = $dedeCommon->addGet($redis_id);
$rightarticlehtml = '';
//如果过期，重新生成一次，再写入缓存
//$result= '';
if($result==''){

	$sql="Select `id`,`title`,`description`,`senddate`,`arcrank`,`litpic`,`color` From
                `dede_archives`  WHERE dede_archives.arcrank =0 AND dede_archives.channel=1 AND dede_archives.flag LIKE '%h%' ORDER BY `id` DESC limit 5";
	$result = $WebDB->query($sql);
	$showlogo='';
	$i = 0;
	while($softrow = $WebDB->fetch_array($result)) {
			$showlogo = $softrow['litpic'];
			$aurl = 'http://news.mumayi.com/article-'.date('Y',$softrow['senddate']).'-'.date('md',$softrow['senddate']).'-'.$softrow['id'].'.html';
			if($softrow['color']){
				$rightarticlehtml.='<li><a href="'.$aurl.'" target="_blank" title="'.$softrow['title'].'"><font color="'.$softrow['color'].'">'.$softrow['title'].'</font></a></li>';
			}else{
				$rightarticlehtml.='<li><a href="'.$aurl.'" target="_blank" title="'.$softrow['title'].'">'.$softrow['title'].'</a></li>';
			}

			$i++;

	}

	$exptime = 3600;
	//写入redis,并设定时间
	$dedeCommon->addTimeSet($redis_id,$exptime,$rightarticlehtml);

}else{
	$rightarticlehtml = $dedeCommon->addGet($redis_id);

}




//Right右侧广告
$redis_id = "softleftfocusad";
$result = $dedeCommon->addGet($redis_id);

//先取到焦点图片
if($result==''){
	$sql="SELECT *  FROM `dede_focusimages` WHERE `cooper` LIKE '%softright%' AND adtype=3 order by pxid desc";
	$result = $WebDB->query($sql);
	$fouceAD = '';
	while($softrow = $WebDB->fetch_array($result)) {
			$focusAD.='<a href="'.$softrow['url'].'" title="'.$softrow['title'].'" target="_blank" ><img alt="'.$softrow['title'].'" width="270" height="130"  src="'.$softrow['imgurls'].'" ></a>';
	}
	$exptime = 3600;
	//写入redis,并设定时间
	$dedeCommon->addTimeSet($redis_id,$exptime,$fouceAD);


}else{
	$focusAD = $dedeCommon->addGet($redis_id);

}

//取到正方形广告图片
$redis_id = "softleftonead";
$result = $dedeCommon->addGet($redis_id);
if($result==''){
	$sql="SELECT *  FROM `dede_focusimages` WHERE `cooper` LIKE '%softright%' AND adtype=2 order by pxid desc";
	$result = $WebDB->query($sql);
	while($softrow = $WebDB->fetch_array($result)) {
			if($softrow['isflash']){
				$rightoneAD[]='<object width="280" height="80" align="middle" id="'.$softrow['title'].'" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="never" name="allowScriptAccess"><param value="high" name="quality"><param value="transparent" name="wmode"><param value="'.$softrow['imgurls'].'" name="movie"><embed width="280" height="80" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="never" quality="high" name="'.$softrow['title'].'" src="'.$softrow['imgurls'].'" wmode="transparent"></object>';
			}else{
				$rightoneAD[]='<a href="'.$softrow['url'].'" title="'.$softrow['title'].'" target="_blank" ><img src="'.$softrow['imgurls'].'" width="250" height="250" alt="'.$softrow['title'].'"></a>';
			}
	}
	$exptime = 3600;
	//写入redis,并设定时间
	$dedeCommon->addTimeSet($redis_id,$exptime,serialize($rightoneAD));


}else{
	$rightoneAD = unserialize($dedeCommon->addGet($redis_id));

}



//取到长方形广告图片
$redis_id = "softlefttwoad";
$result = $dedeCommon->addGet($redis_id);
if($result==''){
	$sql = "SELECT *  FROM `dede_focusimages` WHERE `cooper` LIKE '%softright%' AND adtype=1 order by pxid desc";
	$result = $WebDB->query($sql);
	while($softrow = $WebDB->fetch_array($result)) {
		if($softrow['isflash']){
			$righttwoAD[]='<object width="280" height="80" align="middle" id="'.$softrow['title'].'" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="never" name="allowScriptAccess"><param value="high" name="quality"><param value="transparent" name="wmode"><param value="'.$softrow['imgurls'].'" name="movie"><embed width="280" height="80" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="never" quality="high" name="'.$softrow['title'].'" src="'.$softrow['imgurls'].'" wmode="transparent"></object>';
		}else{
			$righttwoAD[]='<a href="'.$softrow['url'].'" title="'.$softrow['title'].'" target="_blank" ><img src="'.$softrow['imgurls'].'" width="280" height="80" alt="'.$softrow['title'].'"></a>';
		}
	}
	$exptime = 3600;
	//写入redis,并设定时间
	$dedeCommon->addTimeSet($redis_id,$exptime,serialize($righttwoAD));

}else{
	$righttwoAD = unserialize($dedeCommon->addGet($redis_id));
}



//你可能也喜欢
//缓存ID
$redis_id="newaddrecommendlist".$typeid;
$result = $dedeCommon->addGet($redis_id);
$recommendlisthtml = '';
//如果过期，重新生成一次，再写入缓存

if($result == ''){
	//先取到此分类，随机相关软件
	$nowtimes = time()-24*3600;
	
	$sql = "SELECT versionname,id,title,icon FROM `mumayi_soft` WHERE sid =0 AND status =2 AND  adminstatus!=20 AND cid = $typeid  AND created<='$nowtimes'  ORDER BY  rand() DESC LIMIT 0 , 6";
	$query = $DEVDB->query($sql);
	while(@$softrow = $DEVDB->fetch_array($query)) {

			$baseIcon = dirname($softrow['icon']).'/litpicH_'.basename($softrow['icon']);
			$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
			if(is_file($iconDir)){
				$showlogo = GetRandImages($baseIcon);
			}else{
				$showlogo = GetRandImages($softrow['icon']);
			}
			$versionname = $softrow['versionname'];
			$title = $softrow['title'];
			$id = $softrow['id'];

			$recommendlisthtml.='<li>
			  <a class="img72_72" title="'.$title.' V'.$versionname.'" target="_blank" href="http://www.mumayi.com/android-'.$id.'.html">
				  <img alt="'.$title.' V'.$versionname.'"  width="72" height="72" src="'.$showlogo.'">
				  <div class="fff72_72"></div>
			  </a>
			  <div class="tit50">
				  <a title="'.$title.' V'.$versionname.'" target="_blank" href="http://www.mumayi.com/android-'.$id.'.html">'.$title.' V'.$versionname.'</a>
			  </div>
			</li>';

	}

	$nowtime = time();

	
	$sql = "SELECT versionname,id,title,icon FROM `mumayi_soft` WHERE sid =0 AND status =2 AND   adminstatus!=20 AND  attribute LIKE '%f%' ORDER BY   created  DESC LIMIT 0 , 6";
	$query = $DEVDB->query($sql);
	while(@$softrow = $DEVDB->fetch_array($query)) {

			$baseIcon = dirname($softrow['icon']).'/litpicH_'.basename($softrow['icon']);
			$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
			if(is_file($iconDir)){
				$showlogo = GetRandImages($baseIcon);
			}else{
				$showlogo = GetRandImages($softrow['icon']);
			}
			$versionname = $softrow['versionname'];
			$title = $softrow['title'];
			$id = $softrow['id'];

			$recommendlisthtml.='<li>
			  <a class="img72_72" title="'.$title.' V'.$versionname.'" target="_blank" href="http://www.mumayi.com/android-'.$id.'.html">
				  <img alt="'.$title.' V'.$versionname.'"  width="72" height="72" src="'.$showlogo.'">
				  <div class="fff72_72"></div>
			  </a>
			  <div class="tit50">
				  <a title="'.$title.' V'.$versionname.'" target="_blank" href="http://www.mumayi.com/android-'.$id.'.html">'.$title.' V'.$versionname.'</a>
			  </div>
			</li>';

	}

	//写入redis,并设定时间
	$dedeCommon->addTimeSet($redis_id,$exptime,$recommendlisthtml);


}else{
	$recommendlisthtml = $dedeCommon->addGet($redis_id);
}


//底部侧推荐6个 MPK游戏
$bottomID = implode(',',array_slice($allMpk, 9,6));
$redis_id = "softbottommpk";
$data = array();
$result = $dedeCommon->addGet($redis_id);
$bottommpkhtml = '';

if($result == ''){
	$sql = "SELECT versionname,id,title,icon FROM `mumayi_soft` WHERE adminstatus=20 AND id IN ($bottomID) ORDER BY id DESC LIMIT 0 , 9";
	$query = $DEVDB->query($sql);
	while(@$softrow = $DEVDB->fetch_array($query)) {

			$baseIcon = dirname($softrow['icon']).'/litpicH_'.basename($softrow['icon']);
			$iconDir = $GLOBALS['UPLOAD_DIR'].$baseIcon;
			if(is_file($iconDir)){
				$showlogo = GetRandImages($baseIcon);
			}else{
				$showlogo = GetRandImages($softrow['icon']);
			}
			$versionname = $softrow['versionname'];
			$title = $softrow['title'];
			$id = $softrow['id'];

			$bottommpkhtml.='<li>
			  <a class="img72_72" title="'.$title.' V'.$versionname.'" target="_blank" href="http://mpk.mumayi.com/'.$id.'.html">
				  <img alt="'.$title.' V'.$versionname.'"  width="72" height="72" src="'.$showlogo.'">
				  <div class="fff72_72"></div>
			  </a>
			  <div class="tit50">
				  <a title="'.$title.' V'.$versionname.'" target="_blank" href="http://mpk.mumayi.com/'.$id.'.html">'.$title.' V'.$versionname.'</a>
			  </div>
		  </li>';

			//写入redis,并设定时间
			$exptime = 2*3600;
			$dedeCommon->addTimeSet($redis_id,$exptime,$bottommpkhtml);
	}
}else{
	$bottommpkhtml = $dedeCommon->addGet($redis_id);
}

$recommendlisthtml = $recommendlisthtml.$bottommpkhtml;

//软件大小
$softsize = trim(sprintf("%0.2f", $softArr['softsize']/(1024*1024))).'MB';

//软件类型：免费，收费等
$datas = readCacheArray('softtype.php');
$softtype = ($datas[$softArr['softtype']])?$datas[$softArr['softtype']]:'免费软件';


//处理系统要求
$datas = readCacheArray('os.php');
$osArr = explode(',',$softArr['os']);
if(is_array($osArr))foreach($osArr as $val){
	$osList[]['os'] = $datas[$val];
}
$osFirst = $osList[0]['os'];
unset($osList[0]);

//处理分辨率
$datas = readCacheArray('resolution.php');
$resolutionArr = explode(',',$softArr['resolution']);
if(is_array($resolutionArr))foreach($resolutionArr as $val){
	$resolutionList[]['resolution'] = $datas[$val];
}
$resolutionFirst = $resolutionList[0]['resolution'];
unset($resolutionList[0]);

$permissionNum = $sum = 0;
//处理权限列表
if($softArr['permission']){

	$permission = @unserialize($softArr['permission']);

	$resultfile = readCacheArray('permisslist.php');

	$data_arr = array();

	if(is_array($permission))foreach($permission as $vals ) {
		$data_arr[] = @$resultfile[$vals];
	}

	$data_list = array_filter($data_arr);

	if(is_array($data_list))foreach($data_list as $c=>$key) {
		$sort_level[] = $key['level'];
	}

	@array_multisort($sort_level, SORT_DESC,$data_list);


	$permissionNum = count($data_list);
	$permissionlist = '';
	if(is_array($data_list))foreach($data_list as $val ) {
			if($val['level'] >= 2){ $sum++; }
			$prompt = '';
			if($val['level']){$prompt = 'class="prompt"';}
			$permissionlist.= '<li class="color_'.$val['level'].'"><span '.$prompt.'></span><b>'.$val['title'].'</b>'.$val['memo'].'</li>';

	}


}

$permission = ($sum)?('<a href="http://www.mumayi.com/android-'.$id.'-2.html#mumayi" >'.$sum.'项关键权限</a>'):('<a href="http://www.mumayi.com/android-'.$id.'-2.html#mumayi" >可放心下载</a>');

//处理广告列表
$adnum = 0;
if($softArr['apkad']){
	$apkadresult = @unserialize($softArr['apkad']);
	$adnum = count($apkadresult);
}
$apkad = ($adnum)?('包含'.$apkadresult[0].'广告等'.$adnum.'项插件'):('未检测到任何广告插件');
//处理开发者信息
$developer = '第七传媒';



//处理评分逻辑
$numrow = $WebDB->fetch_first("select softrank,scoretotal,scorenum FROM `dede_addonsoft` where aid=$id ");
//a.先取编辑评分*10得到总分
$edittotal=trim($numrow['softrank'])*10;

//b.再取到网友评分
$othertotal = trim($numrow['scoretotal']);
$softrankbigs = (int)(($edittotal+$othertotal)/($numrow['scorenum']+10));
$score = $softrankbigs*10;
if($score > 50) $score=50;
if($score < 10) $score=10;
$scorenum = $numrow['scorenum']+10;

if($score<=10){$scoretext='不给力';}
if($score>10&&$score<=20){$scoretext='一般般';}
if($score>20&&$score<=30){$scoretext='一般';}
if($score>30&&$score<=40){$scoretext='还不错';}
if($score>40){$scoretext='强烈推荐';}




//处理前台下载量
$frontdownload = FormatDownNum($softArr['frontdownload']);


//处理软件缩图片列表
$sql = "SELECT path FROM `mumayi_soft_image`  where  sid = $id ";
$query = $DEVDB->query($sql);
$imgdata = array();
$i = 0;
while(@$row = $DEVDB->fetch_array($query)) {
		$imgdir = $GLOBALS['UPLOAD_DIR'].$row['path'];
		//取到图片宽高
		list($width, $height, $type, $attr) = @getimagesize($imgdir);
		if($i){
			$imgdata[]['path'] = '<img width="'.$width.'" height="'.$height.'"  alt="'.$softArr['title'].' V'.$softArr['versionname'].'" src2="'.GetRandImages($row['path']).'">';
		}else{
			$imgdata[]['path'] = '<img width="'.$width.'" height="'.$height.'" id="headimgShow" alt="'.$softArr['title'].' V'.$softArr['versionname'].'" src2="'.GetRandImages($row['path']).'">';
		}
		$i++;
}

$videoNum = $packetNum = $versionNum = $packetNum = $raidersNum = 0;

//计算视频量
$videoData = array();
$sqlone = "SELECT * FROM `mumayi_soft_video`  where sid=$id";
$query = $DEVDB->query($sqlone);
$i = 0;
while(@$row = $DEVDB->fetch_array($query)) {
		$videoData[$i]['title'] = $row['title'];
		$videoData[$i]['path'] = $row['path'];
		$i++;
}
$videoNum = count($videodata);



//计算历史版本量
$versionData = array();
$sqlone = "SELECT * FROM `dede_version`  where aid=$id  ORDER BY `id` DESC";
$query = $WebDB->query($sqlone);
$i = 0;
while(@$row = $WebDB->fetch_array($query)) {
		$versionData[$i]['softsize'] = $row['softsize'];
		$versionData[$i]['versioncode'] = $row['versioncode'];
		$versionData[$i]['created'] = date('Y-m-d',$row['created']);
		$versionData[$i]['downnum'] = $row['downnum'];
		$versionData[$i]['id'] = $row['id'];
		$versionData[$i]['aid'] = $row['aid'];
		$versionData[$i]['logs'] = $row['logs'];
		$i++;
}

$versionNum = count($versionData);



//取到软件数据包
$packetData = array();
$sqlone = "SELECT * FROM `dede_packet`  where aid=$id  ORDER BY `id` DESC";
$query = $WebDB->query($sqlone);
$i = 0;
while(@$row = $WebDB->fetch_array($query)) {
		$packetData[$i]['url'] = $row['url'];
		$packetData[$i]['title'] = $row['name'];
		$i++;
}


$packetNum = count($packetData);


/*****处理论坛帖子，此数据会在bbs.php调用******/

//处理软件中文搜索，如果有中文，则用中文搜索论坛帖子
$softtitle = trim($softArr['title']);
if(preg_match_all("/[\x{4e00}-\x{9fa5}]+/u",$softtitle,$titlecontent)){
	$softtitle = $titlecontent[0][0];
}

//先取到刷新会变的URL参数值
//$curldata = CurlHttp(array(0=>'http://bbss.mumayi.com/'),'3');//调用
$pagecontent = $curldata['content'][0];
if($pagecontent){
	preg_match_all("/href=\"\/f\/search([\s\S]+?)\"/i",$pagecontent,$content);
}
$page = ($page)?$page:1;
//urlencode 编辑中文搜索关键词
$url = 'http://bbss.mumayi.com/f/search'.preg_replace('/q=([\s\S]+?)&/', "q=".urlencode($softtitle)."&amp;", $content[1][0]).'&page='.$page;

//处理&符号编码问题
$url = str_replace('&amp;','&',$url);

//Curl抓取论坛搜索内容的信息
//$curldata = CurlHttp(array(0=>$url),'10');//调用
$pagecontent = $curldata['content'][0];

//处理论坛下载总量
$redis_id = "softbbstotal".$id;
$result = $dedeCommon->addGet($redis_id);
//如果过期，重新生成一次，再写入缓存
if($result == ''){
	$oneurl = 'http://bbss.mumayi.com/f/search'.preg_replace('/q=([\s\S]+?)&/', "q=".urlencode($softtitle)."&amp;", $content[1][0]).'&page=1';
	$oneurl = str_replace('&amp;','&',$oneurl);
	//$onecurldata = CurlHttp(array(0=>$oneurl),'3');//调用
	$onepagecontent = $onecurldata['content'][0];
	if($onepagecontent){
		preg_match_all("/<div(.*)class=\"allnum\">([\s\S]+?)<\/div>/i",$onepagecontent,$content);

		preg_match_all("/[\d,]+/i",trim($content[2][0]),$content);
		//总搜索到相关帖子的总量
		$bbstotal = str_replace(',','',$content[0][0]);
	}

	/*****处理论坛帖子，此数据会在bbs.php调用******/

	$bbstotal = FormatBbsNum($bbstotal);

	$exptime = 3600*10;
	//写入redis,并设定时间
	$dedeCommon->addTimeSet($redis_id,$exptime,$bbstotal);

}else{
	$bbstotal = $dedeCommon->addGet($redis_id);
}
$bbstotal = 0;

//处理导航页
if(!in_array($softListType,array(2,3,4,5,6,20))){
	$navList = '<li class="current"><a href="android-'.$softId.'.html" title="'.$softArr['title'].'内容介绍">内容介绍</a></li>';
}else{
	$navList = '<li><a href="android-'.$softId.'.html" title="'.$softArr['title'].'内容介绍">内容介绍</a></li>';
}

if($permissionNum){
	if($softListType == 2){
		$navList.= '<li class="current"><a href="android-'.$softId.'-2.html#mumayi" title="'.$softArr['title'].'权限">权限('.$permissionNum.')</a></li>';
	}else{
		$navList.= '<li><a href="android-'.$softId.'-2.html#mumayi" title="'.$softArr['title'].'权限">权限('.$permissionNum.')</a></li>';
	}
}

if($bbstotal){
	if($softListType == 6){
		$navList.= '<li class="current"><a href="android-'.$softId.'-6.html#mumayi" title="'.$softArr['title'].'论坛讨论">讨论('.$bbstotal.')</a></li>';
	}else{
		$navList.= '<li><a href="android-'.$softId.'-6.html#mumayi" title="'.$softArr['title'].'论坛讨论">讨论('.$bbstotal.')</a></li>';
	}
}


if($videoNum){
	if($softListType == 3){
		$navList.= '<li class="current"><a href="android-'.$softId.'-3.html#mumayi" title="'.$softArr['title'].'视频">视频('.$videoNum.')</a></li>';
	}else{
		$navList.= '<li><a href="android-'.$softId.'-3.html#mumayi" title="'.$softArr['title'].'视频">视频('.$videoNum.')</a></li>';
	}
}


if($raidersNum){
	if($softListType == 4){
		$navList.= '<li class="current"><a href="android-'.$softId.'-4.html#mumayi" title="'.$softArr['title'].'攻略">攻略('.$raidersNum.')</a></li>';
	}else{
		$navList.= '<li><a href="android-'.$softId.'-4.html#mumayi" title="'.$softArr['title'].'攻略">攻略('.$raidersNum.')</a></li>';
	}
}

if(empty($isdelete)){
	if($versionNum){
		if($softListType == 5){
			$navList.= '<li class="current"><a href="android-'.$softId.'-5.html#mumayi" title="'.$softArr['title'].'历史版本">历史版本('.$versionNum.')</a></li>';
		}else{
			$navList.= '<li><a href="android-'.$softId.'-5.html#mumayi" title="'.$softArr['title'].'历史版本">历史版本('.$versionNum.')</a></li>';
		}
	}
}

if($packetNum){
	if($softListType == 20){
		$navList.= '<li class="current"><a href="android-'.$softId.'-20.html#mumayi" title="'.$softArr['title'].'数据包">数据包('.$packetNum.')</a></li>';
	}else{
		$navList.= '<li><a href="android-'.$softId.'-20.html" title="'.$softArr['title'].'数据包">数据包('.$packetNum.')</a></li>';
	}
}

//汉化标签
if(strpos($softArr['attribute'],'s')===false) {
    $ishanhua =0;
}else{
    $ishanhua =1;
}
